/**********************************************
 * 
 * File Name				:	UserManagementDAOImpl.java
 * 
 * Last Changed Date		: 	$Date: 2009-08-01 11:12:53 +0800 (星期六, 01 八月 2009) $
 * 
 * Last Changed Revision	:	$Revision: 86 $
 * 
 * Last Changed Author		:	$Author: cfanboy $
 * 
 * File Header URL			:	$HeadURL: svn://www.svnhost.cn/Busi-Building/code/branch/src/com/busibuilding/administrate/security/dao/UserManagementDAOImpl.java $
 * 
 * ********************************************
 */

package com.busibuilding.administrate.security.dao;

import java.util.List;

import com.busibuilding.administrate.security.vo.UserCVO;
import com.busibuilding.common.config.sqlmap.entities.MenuVO;
import com.busibuilding.common.dao.CommonDaoImpl;
import com.busibuilding.common.exceptions.DAOException;
import com.busibuilding.common.vo.ICommonVO;

/**
 * Class Name: UserManagementDAOImpl.java
 * Description: 
 * @author YU Zhipeng
 * @version 1.0
 * @since 1.0
 * Date: 2009-7-20
 */

@SuppressWarnings("unchecked")
public class UserManagementDAOImpl extends CommonDaoImpl implements
		UserManagementDAO {

	/**
	 * Delete the user
	 * @param vo
	 * @return int The records count of deleted
	 * @throws DAOException
	 */
	@Override
	public int delete(ICommonVO vo) throws DAOException {
		int result = SQLMAP_COMMON_RESULT_ERROR;
		result = delete(CMD_SQL_MAP_SECURITY_DELETE_USER, vo);
		return result;
	}

	/**
	 * Insert the user
	 * @param vo
	 * @return int The Primary key of just inserted.
	 * @throws DAOException
	 */
	@Override
	public int insert(ICommonVO vo) throws DAOException {
		int result = SQLMAP_COMMON_RESULT_ERROR;
		result = (Integer)insert(CMD_SQL_MAP_SECURITY_INSERT_USER, vo);
		return result;
	}

	/**
	 * Search the user by condition
	 * @param vo
	 * @return List The user matched the condition.
	 * @throws DAOException
	 */
	@Override
	public List<UserCVO> searchUserByCondition(ICommonVO vo)
			throws DAOException {
		return queryList(CMD_SQL_MAP_SECURITY_SEARCH_USER_BY_CONDITION, vo);
	}

	/**
	 * Search the user by condition use pagination
	 * @param vo
	 * @param skipResults The records count will be skipped.
	 * @param maxResults The records count need to be got.
	 * @return List The user matched the condition
	 * @throws DAOException
	 */
	@Override
	public List<UserCVO> searchUserByCondition(ICommonVO vo, int skipResults,
			int maxResults) throws DAOException {
		return queryList(CMD_SQL_MAP_SECURITY_SEARCH_USER_BY_CONDITION, vo, skipResults, maxResults);
	}

	/**
	 * Update the user
	 * @param vo
	 * @return int The records count of updated. if equal 0 will be thrown the OptimisticLockException.
	 * @throws DAOException
	 */
	@Override
	public int update(ICommonVO vo) throws DAOException {
		int result = SQLMAP_COMMON_RESULT_ERROR;
		result = update(CMD_SQL_MAP_SECURITY_UPDATE_USER, vo);
		return result;
	}

	@Override
	public List<MenuVO> getBelongToUserMenus(ICommonVO vo) throws DAOException {
		return queryList(CMD_SQL_MAP_SECURITY_GET_BELONG_TO_USER_MENUS, vo);
	}

}
